package com.qf.controller;

import com.qf.pojo.TbUser;
import com.qf.pojo.req.TbUserReq;
import com.qf.pojo.resp.BaseResult;
import com.qf.service.TbUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.Map;

@RestController
@RequestMapping("/user")
public class TbUserController {
    @Autowired
    TbUserService tbUserService;

    @RequestMapping("/login")
    public BaseResult login(@RequestBody TbUser tbUser, HttpSession session){
        BaseResult result = tbUserService.login(tbUser, session);
        System.out.println("登录结果："+result);
        return result;
    }


    @RequestMapping("/sendMail")
    public BaseResult sendMail(@RequestBody Map map){
        BaseResult mail = tbUserService.sendMail(map.get("userName").toString());
        System.out.println("邮件发送结果："+mail);
        return mail;
    }

    @RequestMapping("/register")
    public BaseResult register(@RequestBody TbUserReq tbUserReq){
        System.out.println("前端传入参数："+tbUserReq);
        BaseResult result = tbUserService.addUser(tbUserReq);
        System.out.println("后端返回结果："+result);
        return result;
    }
}
